package com.generate.service;

import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ytj
 * @date 2021/5/31
 */
@Service
public class DataService {

    /**
     * 通过jdbc方式查询数据库中表名称
     * */
    public List<String> tableList(String url,String className,String user,String password) throws Exception{
        List<String> list=new ArrayList<>();
        Class.forName(className);
        Connection connection= DriverManager.getConnection(url,user,password);
        Statement stream=connection.createStatement();
        String sql="select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = 'backg'";
        ResultSet resultSet=stream.executeQuery(sql);
        while (resultSet.next()){
            String str=resultSet.getString("TABLE_NAME");
            list.add(str);
        }
        resultSet.close();
        stream.close();
        connection.close();
        return list;
    }

    /**
     * 代码生成
     * */
    public void writeCode(){

    }
}
